<template>
  <div class="login">
    <div class="bg"></div>
    <div class="admin-login">
      <div class="login-header">
        <img src="../assets/images/login/u4.png" alt="" />
      </div>
      <div class="login-body">
        <p><span>后台业务管理系统</span></p>
        <el-form
          :model="ruleForm"
          ref="ruleForm"
          label-width="100px"
          class="demo-ruleForm m-t"
        >
          <el-input
            class="ipt-top"
            v-model="ruleForm.name"
            prefix-icon="el-icon-user"
            placeholder="请输入账号"
          ></el-input>
          <el-input
            class="ipt-top"
            show-password
            v-model="ruleForm.pwd"
            prefix-icon="el-icon-lock"
            placeholder="请输入密码"
          ></el-input>
          <el-button type="primary" class="login-submit" @click="isLogin()"
            >登陆</el-button
          >
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 登录表单数据
      ruleForm: {
        name: '',
        pwd: ''
      }
    }
  },
  methods: {
    async isLogin() {
      const { data: res } = await this.$http.get('/login', {
        params: {
          username: this.ruleForm.name,
          password: this.ruleForm.pwd
        }
      })
      if (res.data.status !== 200) {
        return this.$Toast('账号或密码错误', 'error')
      }
      this.$Toast('登录成功', 'success')
      console.log(res)
      window.sessionStorage.setItem(
        'username',
        JSON.stringify(res.data.username)
      )
      window.sessionStorage.setItem('token', res.data.token)
      //   return this.$Toast()
      this.$router.history.push('/index')
    }
  }
}
</script>

<style lang="less" scope>
.login {
  height: 100%;
  position: relative;
  .bg {
    position: absolute;
    top: 50%;
    height: 220px;
    width: 100%;
    transform: translateY(-50%);
    background: #039aff;
    background-image: url('../assets/images/login/u0_state0.png');
    background-position: center;
  }
  .admin-login {
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 350px;
    height: 420px;
    background: #fff;
    .login-header {
      font-size: 0px;
      img {
        vertical-align: middle;
      }
    }
    .login-body {
      margin-top: 98px;
      text-align: center;
      p {
        span {
          font-size: 24px;
          font-weight: 700;
          color: #039aff;
        }
      }
    }
  }
}

.login-submit {
  width: 100%;
  margin-top: 10px !important;
}
.login-params {
  margin-top: 20px;
  text-align: center;
}
.m-t {
  padding: 0 30px;
  margin-top: 20px;
}
.ipt-top {
  margin-top: 20px;
}
// .el-form-item__content {
//   margin-left: 60px !important;
//   margin-right: 30px;
// }
.pl {
  font-size: 14px;
  width: 100px;
  height: 40px;
  padding-right: 12px;
  display: inline-block;
  line-height: 40px;
  padding-left: 28px;
}
.add-cs {
  text-align: left;
}
</style>
